﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Koala
{
    public partial class ConnectionForm : Form
    {
        private NodeTree newnode;
        private bool _success;

        public NodeTree GetNode()
        {
            return newnode;
        }

        public bool Success
        {
            get { return _success; }
        }

        public ConnectionForm()
        {
            _success = false;
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            newnode = new NodeTree(txtHost.Text, numPort.Value.ToString(), txtDB.Text, txtUsername.Text, txtPass.Text);

            if (newnode.Connect())
            {
                _success = true;
                Close();
            }
            else
            {
                _success = false;
                MessageBox.Show("Connection Failed",
                                "Can't connect to the host " + txtHost.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
    }
}
